/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.uniminuto.edu.videominuto.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Juan
 */
@Entity
@Table(name = "transaccion")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Transaccion.findAll", query = "SELECT t FROM Transaccion t"),
    @NamedQuery(name = "Transaccion.findByIdTransaccion", query = "SELECT t FROM Transaccion t WHERE t.transaccionPK.idTransaccion = :idTransaccion"),
    @NamedQuery(name = "Transaccion.findByIdCliente", query = "SELECT t FROM Transaccion t WHERE t.transaccionPK.idCliente = :idCliente"),
    @NamedQuery(name = "Transaccion.findByIdTipoTransaccion", query = "SELECT t FROM Transaccion t WHERE t.transaccionPK.idTipoTransaccion = :idTipoTransaccion"),
    @NamedQuery(name = "Transaccion.findByIdVideo", query = "SELECT t FROM Transaccion t WHERE t.transaccionPK.idVideo = :idVideo"),
    @NamedQuery(name = "Transaccion.findByFechaInicio", query = "SELECT t FROM Transaccion t WHERE t.transaccionPK.fechaInicio = :fechaInicio"),
    @NamedQuery(name = "Transaccion.findByCantReproducciones", query = "SELECT t FROM Transaccion t WHERE t.cantReproducciones = :cantReproducciones"),
    @NamedQuery(name = "Transaccion.findByDiasAlquiler", query = "SELECT t FROM Transaccion t WHERE t.diasAlquiler = :diasAlquiler"),
    @NamedQuery(name = "Transaccion.findByValorTransaccion", query = "SELECT t FROM Transaccion t WHERE t.valorTransaccion = :valorTransaccion")})
public class Transaccion implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected TransaccionPK transaccionPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "cant_reproducciones")
    private int cantReproducciones;
    @Basic(optional = false)
    @NotNull
    @Column(name = "dias_alquiler")
    private int diasAlquiler;
    @Basic(optional = false)
    @NotNull
    @Column(name = "valor_transaccion")
    private int valorTransaccion;
    @JoinColumn(name = "id_video", referencedColumnName = "id_video", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Video video;
    @JoinColumn(name = "id_tipo_transaccion", referencedColumnName = "id_tipo_transaccion", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private TipoTransaccion tipoTransaccion;
    @JoinColumn(name = "id_cliente", referencedColumnName = "id_cliente", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Cliente cliente;

    public Transaccion() {
    }

    public Transaccion(TransaccionPK transaccionPK) {
        this.transaccionPK = transaccionPK;
    }

    public Transaccion(TransaccionPK transaccionPK, int cantReproducciones, int diasAlquiler, int valorTransaccion) {
        this.transaccionPK = transaccionPK;
        this.cantReproducciones = cantReproducciones;
        this.diasAlquiler = diasAlquiler;
        this.valorTransaccion = valorTransaccion;
    }

    public Transaccion(int idTransaccion, int idCliente, int idTipoTransaccion, int idVideo, Date fechaInicio) {
        this.transaccionPK = new TransaccionPK(idTransaccion, idCliente, idTipoTransaccion, idVideo, fechaInicio);
    }

    public TransaccionPK getTransaccionPK() {
        return transaccionPK;
    }

    public void setTransaccionPK(TransaccionPK transaccionPK) {
        this.transaccionPK = transaccionPK;
    }

    public int getCantReproducciones() {
        return cantReproducciones;
    }

    public void setCantReproducciones(int cantReproducciones) {
        this.cantReproducciones = cantReproducciones;
    }

    public int getDiasAlquiler() {
        return diasAlquiler;
    }

    public void setDiasAlquiler(int diasAlquiler) {
        this.diasAlquiler = diasAlquiler;
    }

    public int getValorTransaccion() {
        return valorTransaccion;
    }

    public void setValorTransaccion(int valorTransaccion) {
        this.valorTransaccion = valorTransaccion;
    }

    public Video getVideo() {
        return video;
    }

    public void setVideo(Video video) {
        this.video = video;
    }

    public TipoTransaccion getTipoTransaccion() {
        return tipoTransaccion;
    }

    public void setTipoTransaccion(TipoTransaccion tipoTransaccion) {
        this.tipoTransaccion = tipoTransaccion;
    }

    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (transaccionPK != null ? transaccionPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Transaccion)) {
            return false;
        }
        Transaccion other = (Transaccion) object;
        if ((this.transaccionPK == null && other.transaccionPK != null) || (this.transaccionPK != null && !this.transaccionPK.equals(other.transaccionPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "co.uniminuto.edu.videominuto.entities.Transaccion[ transaccionPK=" + transaccionPK + " ]";
    }
    
}
